#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
struct Node {
  int op, x;
} q[N];
int a[N], num;
int sum[N << 2];
void update(int x, int d, int p, int l, int r) {
  sum[p] += d;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(x, d, p << 1, l, mid);
  else
    update(x, d, p << 1 | 1, mid + 1, r);
}
int query(int L, int R, int p, int l, int r) {
  if (L > R) return 0;
  if (L <= l && R >= r) return sum[p];
  int mid = (l + r) >> 1;
  int res = 0;
  if (L <= mid) res += query(L, R, p << 1, l, mid);
  if (R > mid) res += query(L, R, p << 1 | 1, mid + 1, r);
  return res;
}
int query(int k, int p, int l, int r) {
  if (l == r) return l;
  int mid = (l + r) >> 1;
  if (sum[p << 1] >= k)
    return query(k, p << 1, l, mid);
  else
    return query(k - sum[p << 1], p << 1 | 1, mid + 1, r);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> q[i].op >> q[i].x;
  rep(i, 1, n) if (q[i].op != 4) a[++num] = q[i].x;
  sort(a + 1, a + num + 1);
  num = unique(a + 1, a + num + 1) - a - 1;
  rep(i, 1, n) {
    if (q[i].op != 4) q[i].x = lower_bound(a + 1, a + num + 1, q[i].x) - a;
    if (q[i].op == 1) update(q[i].x, 1, 1, 1, num);
    if (q[i].op == 2) update(q[i].x, -1, 1, 1, num);
    if (q[i].op == 3) cout << query(1, q[i].x - 1, 1, 1, num) + 1 << endl;
    if (q[i].op == 4) cout << a[query(q[i].x, 1, 1, num)] << endl;
    if (q[i].op == 5) {
      int k = query(1, q[i].x - 1, 1, 1, num);
      cout << a[query(k, 1, 1, num)] << endl;
    }
    if (q[i].op == 6) {
      int k = query(1, q[i].x, 1, 1, num) + 1;
      cout << a[query(k, 1, 1, num)] << endl;
    }
  }
  return 0;
}